package com.share.thread.pc;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @desc:
 * @author:caifan
 * @date:2022/1/28
 */
public class Producer02 implements Runnable {
    private MyBlockingForCondition queue;
    private AtomicInteger atomic = new AtomicInteger(1);

    public Producer02(MyBlockingForCondition queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                int i = atomic.getAndIncrement();
                queue.put(i);
                System.out.println("producer:" + i + "-" + Thread.currentThread().getName());
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
